package mall.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import mall.pojo.Industry;

@Repository
public class IndustryDAOImpl implements IndustryDAO {
	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public List<Industry> listIndustry() {
		String hql = "FROM Industry";
		Query query = sessionFactory.getCurrentSession().createQuery(hql);
		return query.list();
	}

	@Override
	public Industry getIndustry() {
		
		return null;
	}

	@Override
	public void createIndustry(Industry industry) {
		sessionFactory.getCurrentSession().save(industry);
	}

	@Override
	public int updateIndustry(Industry industry) {
		String hql="UPDATE industry SET name = :name WHERE id = :id";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter("name", industry.getName());
		query.setParameter("id", industry.getId());
		return query.executeUpdate();
	}

}
